package com.example.testapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class TabButtonActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    private TextView tv_tab_button; // 声明一个标签按钮对象
    private CheckBox ck_select; // 声明一个复选框

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_button);
        tv_tab_button = findViewById(R.id.tv_tab_button);
        tv_tab_button.setOnClickListener(this);
        ck_select = findViewById(R.id.ck_select);
        ck_select.setOnCheckedChangeListener(this);
    }

    @Override
    public void onClick(View view) {
        if(view.getId() == R.id.tv_tab_button){
            // 将复选框的状态置反
            ck_select.setChecked(!ck_select.isChecked());
        }

    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if(compoundButton.getId() == R.id.ck_select){
            // 设置标签按钮的选中状态
            tv_tab_button.setSelected(b);
        }

    }
}